New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

undios

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

undios

Fetch-based axios-style HTTP client

  • 0.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Undios

Fetch-based axios-style HTTP client.

"und" comes from undici, an HTTP/1.1 client officially supported by Node.js team.

"ios" comes from axios, a popular HTTP client for browser and Node.js.

Features

  • Browser and Node.js support
  • Proxy agents (HTTP / HTTPS / SOCKS)
  • WebSocket

Basic Usage

import Undios from 'undios'

const http = new Undios()

const data = await http.get('https://example.com')
const data = await http.post('https://example.com', body)
const { status, data } = await http('https://example.com', { method: 'GET' })

API

Instance Methods

http(url, config?)
interface HTTP {
  <K extends keyof ResponseTypes>(url: string, config: Config & { responseType: K }): Promise<Response<ResponseTypes[K]>>
  <T = any>(url: string | URL, config?: Config): Promise<Response<T>>
}

Send a request.

http.[get|delete|head](url, config?)
interface HTTP {
  get: Request1
  delete: Request1
  head(url: string, config?: Config): Promise<Headers>
}

interface Request1 {
  <K extends keyof ResponseTypes>(url: string, config: Config & { responseType: K }): Promise<ResponseTypes[K]>
  <T = any>(url: string, config?: Config): Promise<T>
}

Send a GET / DELETE / HEAD request.

http.[post|put|patch](url, data, config?)
interface HTTP {
  patch: Request2
  post: Request2
  put: Request2
}

interface Request2 {
  <K extends keyof ResponseTypes>(url: string, data: any, config: Config & { responseType: K }): Promise<ResponseTypes[K]>
  <T = any>(url: string, data?: any, config?: Config): Promise<T>
}
http.ws(url, config?)
interface HTTP {
  ws(url: string | URL, config?: Config): WebSocket
}

Open a WebSocket connection.

[!NOTE]

Currently we will use ws package to polyfill WebSocket in Node.js.

Once Node.js has a stable WebSocket API, we will switch to it.

Config

interface Config {
  baseURL?: string
  method?: Method
  headers?: Record<string, string>
  redirect?: RequestRedirect
  keepAlive?: boolean
  params?: Record<string, any>
  data?: any
  responseType?: keyof ResponseTypes
  timeout?: number
}
config.baseURL

The base URL of the request. If it is set, the url will be resolved against it.

See URL#base.

config.method

See fetch#method.

config.headers

See fetch#headers.

config.redirect

See fetch#redirect.

config.keepAlive

See fetch#keepalive.

config.params

Additional query parameters. They will be appended to the URL.

config.data

The request body. Currently support below types:

  • string
  • URLSearchParams
  • ArrayBuffer / ArrayBufferView
  • Blob
  • FormData
  • Object (will be serialized to JSON)
config.responseType

Supported response types:

interface ResponseTypes {
  json: any
  text: string
  stream: ReadableStream<Uint8Array>
  blob: Blob
  formdata: FormData
  arraybuffer: ArrayBuffer
}
config.timeout

The request timeout in milliseconds.

config.proxyAgent

[!NOTE]

In order to use a proxy agent, you need to install undios-proxy-agent.

Response

interface Response<T> {
  status: number
  statusText: string
  headers: Headers
  data: T
}
response.status

See Response#status.

response.statusText

See Response#statusText.

response.headers

See Response#headers.

response.data

The decoded response body.

Static Methods

class Undios {
  constructor(config?: Config)
}
Undios.Error.is(error)
function is(error: any): error is Undios.Error

Keywords

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc